package com.xm.httpapi.Aspect;

import com.xm.httpapi.Annotation.DelayOver;
import com.xm.httpapi.Collection.NoEmptyHashMap;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import io.reactivex.disposables.Disposable;
@Aspect
public class DelayOverAspect {
    private static final String POINTCUT_METHOD = "execution(@com.xm.httpapi.Annotation.DelayOver * *(..))";

    @Pointcut(POINTCUT_METHOD)
    public void onDelayOverMethod() {
    }

    @Around("onDelayOverMethod() && @annotation(delayOver)")
    public Object doDelayOverMethod(final ProceedingJoinPoint joinPoint, DelayOver delayOver) throws Throwable {
        String key = delayOver.key();
        Disposable subscribe = (Disposable) NoEmptyHashMap.getInstance().get(key);
        if (subscribe != null){
            subscribe.dispose();
            NoEmptyHashMap.getInstance().remove(key);
        }
        return joinPoint.proceed();
    }
}
